package com.itheima.web;

import com.alibaba.fastjson.JSON;
import com.itheima.pojo.Area;
import com.itheima.service.AreaService;
import com.itheima.service.impl.AreaServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ByIdServlet", value = "/ByIdServlet")
public class ByIdServlet extends HttpServlet {
    private AreaService areaService = new AreaServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String value = request.getParameter("pid");
        List<Area> areas = areaService.selectById(Integer.parseInt(value));
        System.out.println(areas);
        String toJSONString = JSON.toJSONString(areas);

        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(toJSONString);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
